//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.zr.test;

import java.math.BigDecimal;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MoneyConvertUtil extends BigDecimal {
    private static final Logger log = LoggerFactory.getLogger(MoneyConvertUtil.class);
    public static final BigDecimal THOUSAND = new BigDecimal(100);
    public static final BigDecimal WAN = new BigDecimal(1000000);
    private static final long serialVersionUID = 1L;

    public MoneyConvertUtil(long val) {
        super(val);
    }

    public static long convertToFen(BigDecimal money) {
        if (null == money) {
            return 0L;
        } else {
            BigDecimal cal = money.multiply(THOUSAND).setScale(2, 4);
            return cal.longValue();
        }
    }

    public static long wanConvertToFen(BigDecimal money) {
        if (null == money) {
            return 0L;
        } else {
            BigDecimal cal = money.multiply(WAN).setScale(6, 4);
            return cal.longValue();
        }
    }

    public static long convertToFen(String money) {
        return StringUtils.isBlank(money) ? 0L : convertToFen(new BigDecimal(money));
    }

    public static String convertToYuan(Long money) {
        if (null == money) {
            return "";
        } else {
            BigDecimal decimal = new BigDecimal(money);
            return decimal.divide(THOUSAND).setScale(2, 4).stripTrailingZeros().toPlainString();
        }
    }

    public static String convertToYuan2Decimal(Long money) {
        if (null == money) {
            return "";
        } else {
            BigDecimal decimal = new BigDecimal(money);
            return decimal.divide(THOUSAND).setScale(2, 4).toPlainString();
        }
    }

    public static String convertToWanYuan(Long money) {
        if (null == money) {
            return "";
        } else {
            BigDecimal decimal = new BigDecimal(money);
            return decimal.divide(WAN).setScale(2, 4).stripTrailingZeros().toPlainString();
        }
    }

    public static String convertToYuan(Long money, int scale) {
        if (null == money) {
            return "";
        } else {
            BigDecimal decimal = new BigDecimal(money);
            return decimal.divide(THOUSAND).setScale(scale, 4).toString();
        }
    }

    public static String convertToYuanNoPoint(Long money) {
        if (null == money) {
            return "";
        } else {
            BigDecimal decimal = new BigDecimal(money);
            return decimal.divide(THOUSAND).setScale(2, 4).stripTrailingZeros().toPlainString();
        }
    }

    public static String convertUpperCN(Long money) {
        if (money != null && money >= 1L) {
            String[] CN_UPPER_NUMBER = new String[]{"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
            String[] CN_UPPER_MONETRAY_UNIT = new String[]{"分", "角", "元", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "兆", "拾", "佰", "仟"};
            String s = money.toString();
            StringBuilder stringBuilder = new StringBuilder();
            int i = 0;

            int size;
            for(size = s.length(); i < size; ++i) {
                char c = s.charAt(i);
                Integer num = Integer.valueOf(String.valueOf(c));
                stringBuilder.append(CN_UPPER_NUMBER[num]);
                stringBuilder.append(CN_UPPER_MONETRAY_UNIT[size - i - 1]);
            }

            String[][] var9 = new String[][]{{"零分", "零"}, {"零角", "零"}, {"零拾", "零"}, {"零佰", "零"}, {"零仟", "零"}, {"零万", "万"}, {"零亿", "亿"}, {"零零", "零"}, {"零元", "元"}};
            size = var9.length;

            for(int var10 = 0; var10 < size; ++var10) {
                String[] replaces = var9[var10];
                replaceUpperCN(stringBuilder, replaces[0], replaces[1]);
            }

            while(stringBuilder.charAt(stringBuilder.length() - 1) == '零') {
                stringBuilder.deleteCharAt(stringBuilder.length() - 1);
            }

            if (stringBuilder.charAt(stringBuilder.length() - 1) == 20803) {
                stringBuilder.append("整");
            }

            return stringBuilder.toString();
        } else {
            return "";
        }
    }

    private static void replaceUpperCN(StringBuilder stringBuilder, String replace, String replaceVal) {
        String s;
        for(s = stringBuilder.toString(); s.indexOf(replace) != -1; s = s.replace(replace, replaceVal)) {
        }

        stringBuilder.setLength(0);
        stringBuilder.append(s);
    }
}
